package com.lockforzookeeper;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * zookeeper分布式锁
 *
 * @author: 顾志杰
 */
@SpringBootApplication
@EnableScheduling
public class LockForZookeeperApplation {

    public static void main(String[] args) {
        SpringApplication.run(LockForZookeeperApplation.class,args);
    }

    @Bean(initMethod = "start",destroyMethod = "close")
    public CuratorFramework getCuratorFramework(){
        /*获取链接*/
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3);
        CuratorFramework client = CuratorFrameworkFactory.newClient(
                "192.168.35.133:2181"
                ,retryPolicy);
        return client;
    }
}
